﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Raven.Client;
using Topics.Radical.Windows.Presentation;
using Topics.Radical.Windows.Presentation.ComponentModel;

namespace Milestone.Presentation
{
	class CompanyEditorViewModel : AbstractViewModel, ICanBeValidated
	{
		readonly IDocumentStore store;

		public CompanyEditorViewModel( IDocumentStore store )
		{
			this.store = store;
		}

		public String CompanyName
		{
			get { return this.GetPropertyValue( () => this.CompanyName ); }
			set { this.SetPropertyValue( () => this.CompanyName, value ); }
		}

		public void Save()
		{
			var company = Model.Parties.Company.CreateNew( this.CompanyName );
			using( var session = this.store.OpenSession() )
			{
				session.Store( company );
				session.SaveChanges();
			}
		}
	}
}
